<?php

namespace Beerus\Modules\DecoCalculator\Actions;

use Doraemon\model\DecoCalculator\DecoCalculatorWhite as mDecoCalculatorWhite;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class hiddenTopWhite extends RowAction
{
    public $name = '取消置顶';

    public function handle($id,Request $request)
    {

        $update_data = [
            'is_top' => mDecoCalculatorWhite::HIDDEN_TOP,
            'top_time' => 0,
            'admin_id' => Admin::user()->id,
        ];
        if (!mDecoCalculatorWhite::updateInfo($update_data, ['id' => $id])) {
            return $this->response()->success('取消装企置顶失败!')->refresh();
        }

        return $this->response()->success('取消装企置顶成功!!')->refresh();
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }
        return $key;
    }

    public function dialog()
    {
        $this->confirm('确定要取消该装企的置顶吗？');
    }
}
